import 'package:distribution_mall_flutter/generated/json/base/json_convert_content.dart';
import 'package:distribution_mall_flutter/entity/pay/list/pay_list_entity.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';

import 'package:hive/hive.dart';


PayListEntity $PayListEntityFromJson(Map<String, dynamic> json) {
  final PayListEntity payListEntity = PayListEntity();
  final List<PayListType>? types = (json['types'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<PayListType>(e) as PayListType).toList();
  if (types != null) {
    payListEntity.types = types;
  }
  return payListEntity;
}

Map<String, dynamic> $PayListEntityToJson(PayListEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['types'] = entity.types.map((v) => v.toJson()).toList();
  return data;
}

extension PayListEntityExtension on PayListEntity {
  PayListEntity copyWith({
    List<PayListType>? types,
  }) {
    return PayListEntity()
      ..types = types ?? this.types;
  }
}

PayListType $PayListTypeFromJson(Map<String, dynamic> json) {
  final PayListType payListType = PayListType();
  final String? type = jsonConvert.convert<String>(json['type']);
  if (type != null) {
    payListType.type = type;
  }
  final String? typeDisplay = jsonConvert.convert<String>(json['typeDisplay']);
  if (typeDisplay != null) {
    payListType.typeDisplay = typeDisplay;
  }
  final bool? typeDisplayable = jsonConvert.convert<bool>(
      json['typeDisplayable']);
  if (typeDisplayable != null) {
    payListType.typeDisplayable = typeDisplayable;
  }
  final List<PayListPlatform>? platforms = (json['platforms'] as List<dynamic>?)
      ?.map(
          (e) => jsonConvert.convert<PayListPlatform>(e) as PayListPlatform)
      .toList();
  if (platforms != null) {
    payListType.platforms = platforms;
  }
  return payListType;
}

Map<String, dynamic> $PayListTypeToJson(PayListType entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['type'] = entity.type;
  data['typeDisplay'] = entity.typeDisplay;
  data['typeDisplayable'] = entity.typeDisplayable;
  data['platforms'] = entity.platforms?.map((v) => v.toJson()).toList();
  return data;
}

extension PayListTypeExtension on PayListType {
  PayListType copyWith({
    String? type,
    String? typeDisplay,
    bool? typeDisplayable,
    List<PayListPlatform>? platforms,
  }) {
    return PayListType()
      ..type = type ?? this.type
      ..typeDisplay = typeDisplay ?? this.typeDisplay
      ..typeDisplayable = typeDisplayable ?? this.typeDisplayable
      ..platforms = platforms ?? this.platforms;
  }
}

PayListPlatform $PayListPlatformFromJson(Map<String, dynamic> json) {
  final PayListPlatform payListPlatform = PayListPlatform();
  final String? platform = jsonConvert.convert<String>(json['platform']);
  if (platform != null) {
    payListPlatform.platform = platform;
  }
  final PaymentMethod? paymentMethod = jsonConvert.convert<PaymentMethod>(
      json['paymentMethod']);
  if (paymentMethod != null) {
    payListPlatform.paymentMethod = paymentMethod;
  }
  final List<PaymentMethod>? channels = (json['channels'] as List<dynamic>?)
      ?.map(
          (e) => jsonConvert.convert<PaymentMethod>(e) as PaymentMethod)
      .toList();
  if (channels != null) {
    payListPlatform.channels = channels;
  }
  return payListPlatform;
}

Map<String, dynamic> $PayListPlatformToJson(PayListPlatform entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['platform'] = entity.platform;
  data['paymentMethod'] = entity.paymentMethod?.toJson();
  data['channels'] = entity.channels?.map((v) => v.toJson()).toList();
  return data;
}

extension PayListPlatformExtension on PayListPlatform {
  PayListPlatform copyWith({
    String? platform,
    PaymentMethod? paymentMethod,
    List<PaymentMethod>? channels,
  }) {
    return PayListPlatform()
      ..platform = platform ?? this.platform
      ..paymentMethod = paymentMethod ?? this.paymentMethod
      ..channels = channels ?? this.channels;
  }
}

PaymentMethod $PaymentMethodFromJson(Map<String, dynamic> json) {
  final PaymentMethod paymentMethod = PaymentMethod();
  final String? methodName = jsonConvert.convert<String>(json['methodName']);
  if (methodName != null) {
    paymentMethod.methodName = methodName;
  }
  final String? methodCode = jsonConvert.convert<String>(json['methodCode']);
  if (methodCode != null) {
    paymentMethod.methodCode = methodCode;
  }
  final String? subTitle = jsonConvert.convert<String>(json['subTitle']);
  if (subTitle != null) {
    paymentMethod.subTitle = subTitle;
  }
  final double? minPrice = jsonConvert.convert<double>(json['minPrice']);
  if (minPrice != null) {
    paymentMethod.minPrice = minPrice;
  }
  final double? maxPrice = jsonConvert.convert<double>(json['maxPrice']);
  if (maxPrice != null) {
    paymentMethod.maxPrice = maxPrice;
  }
  final bool? isUsable = jsonConvert.convert<bool>(json['isUsable']);
  if (isUsable != null) {
    paymentMethod.isUsable = isUsable;
  }
  final bool? displayable = jsonConvert.convert<bool>(json['displayable']);
  if (displayable != null) {
    paymentMethod.displayable = displayable;
  }
  final String? icon = jsonConvert.convert<String>(json['icon']);
  if (icon != null) {
    paymentMethod.icon = icon;
  }
  final List<
      PaymentMethodClientBank>? paymentMethodClientBank = (json['paymentMethodClientBank'] as List<
      dynamic>?)?.map(
          (e) =>
      jsonConvert.convert<PaymentMethodClientBank>(
          e) as PaymentMethodClientBank).toList();
  if (paymentMethodClientBank != null) {
    paymentMethod.paymentMethodClientBank = paymentMethodClientBank;
  }
  return paymentMethod;
}

Map<String, dynamic> $PaymentMethodToJson(PaymentMethod entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['methodName'] = entity.methodName;
  data['methodCode'] = entity.methodCode;
  data['subTitle'] = entity.subTitle;
  data['minPrice'] = entity.minPrice;
  data['maxPrice'] = entity.maxPrice;
  data['isUsable'] = entity.isUsable;
  data['displayable'] = entity.displayable;
  data['icon'] = entity.icon;
  data['paymentMethodClientBank'] =
      entity.paymentMethodClientBank?.map((v) => v.toJson()).toList();
  return data;
}

extension PaymentMethodExtension on PaymentMethod {
  PaymentMethod copyWith({
    String? methodName,
    String? methodCode,
    String? subTitle,
    double? minPrice,
    double? maxPrice,
    bool? isUsable,
    bool? displayable,
    String? icon,
    List<PaymentMethodClientBank>? paymentMethodClientBank,
  }) {
    return PaymentMethod()
      ..methodName = methodName ?? this.methodName
      ..methodCode = methodCode ?? this.methodCode
      ..subTitle = subTitle ?? this.subTitle
      ..minPrice = minPrice ?? this.minPrice
      ..maxPrice = maxPrice ?? this.maxPrice
      ..isUsable = isUsable ?? this.isUsable
      ..displayable = displayable ?? this.displayable
      ..icon = icon ?? this.icon
      ..paymentMethodClientBank = paymentMethodClientBank ??
          this.paymentMethodClientBank;
  }
}

PaymentMethodClientBank $PaymentMethodClientBankFromJson(
    Map<String, dynamic> json) {
  final PaymentMethodClientBank paymentMethodClientBank = PaymentMethodClientBank();
  final String? clientId = jsonConvert.convert<String>(json['clientId']);
  if (clientId != null) {
    paymentMethodClientBank.clientId = clientId;
  }
  final String? bankId = jsonConvert.convert<String>(json['bankId']);
  if (bankId != null) {
    paymentMethodClientBank.bankId = bankId;
  }
  final String? bankName = jsonConvert.convert<String>(json['bankName']);
  if (bankName != null) {
    paymentMethodClientBank.bankName = bankName;
  }
  final String? bankCode = jsonConvert.convert<String>(json['bankCode']);
  if (bankCode != null) {
    paymentMethodClientBank.bankCode = bankCode;
  }
  final String? status = jsonConvert.convert<String>(json['status']);
  if (status != null) {
    paymentMethodClientBank.status = status;
  }
  return paymentMethodClientBank;
}

Map<String, dynamic> $PaymentMethodClientBankToJson(
    PaymentMethodClientBank entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['clientId'] = entity.clientId;
  data['bankId'] = entity.bankId;
  data['bankName'] = entity.bankName;
  data['bankCode'] = entity.bankCode;
  data['status'] = entity.status;
  return data;
}

extension PaymentMethodClientBankExtension on PaymentMethodClientBank {
  PaymentMethodClientBank copyWith({
    String? clientId,
    String? bankId,
    String? bankName,
    String? bankCode,
    String? status,
  }) {
    return PaymentMethodClientBank()
      ..clientId = clientId ?? this.clientId
      ..bankId = bankId ?? this.bankId
      ..bankName = bankName ?? this.bankName
      ..bankCode = bankCode ?? this.bankCode
      ..status = status ?? this.status;
  }
}